﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using Chefbook.DataObjects;
using System.Globalization;
using Chefbook.DataAccessLayer;

namespace Chefbook.UserActions
{
    public class DeleteCategoryAction : UserActionBase
    {
        private Category categoryToDelete, oldParent;
        private List<Recipe> recipeList;


        public DeleteCategoryAction(Category categoryToDelete)
        {
            this.categoryToDelete = categoryToDelete;
            recipeList = new List<Recipe>(categoryToDelete.DirectRecipes);
            oldParent = categoryToDelete.Parent;
        }

        public override void DoAction()
        {
            base.DoAction();
            DatabaseConnector.DeleteObject(categoryToDelete);
        }

        public override void UndoAction()
        {
            base.UndoAction();
            categoryToDelete.Parent = oldParent;
            foreach (var recipe in recipeList)
            {
                categoryToDelete.AddRecipe(recipe);
            }
        }

        public override string ToString()
        {
            return string.Format(CultureInfo.CurrentUICulture, "Delete Category '{0}'", categoryToDelete);
        }
    }
}
